package com.yswee.mallnavi.view.brand.hor;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import com.yswee.framework.utils.ViewInject;
import com.yswee.framework.widget.layoutview.MRelativeLayout;
import com.yswee.mallnavi.R;
import com.yswee.mallnavi.entity.info.BrandEntity;
import com.yswee.mallnavi.view.brand.IGridView;
import com.yswee.mallnavi.view.brand.grid.GridItem;


public class HListItem extends MRelativeLayout<BrandEntity> {

	@ViewInject
	private GridItem grditem0;
	@ViewInject
	private GridItem grditem1;

	private IGridView.IActionCallback mActionCallback;

	public void setActionCallback(IGridView.IActionCallback c) {
		mActionCallback = c;
	}

	public HListItem(Context context) {
		super(context);
	}

	public HListItem(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected int getLayoutResId() {
		return R.layout.view_info_brand_hlistitem;
	}
	
	@Override
	protected void onBindListener() {
		super.onBindListener();
		grditem0.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (mActionCallback != null) {
					mActionCallback.onBrandClicked(v, mDataItem);
				}
			}
		});
		grditem1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (mDataItem.bottom == null) {
					return;
				}
				if (mActionCallback != null) {
					mActionCallback.onBrandClicked(v, mDataItem.bottom);
				}
			}
		});
	}

	@Override
	protected void onApplyData() {
		grditem0.setDataSource(mDataItem);
		if (mDataItem.bottom != null) {
			grditem1.setDataSource(mDataItem.bottom);
			grditem1.setVisibility(View.VISIBLE);
		} else {
			grditem1.setVisibility(View.INVISIBLE);
		}
	}

}
